<!--
 Copyright (C) 2004 by Alain Bienvenue. All rights reserved.
 Released under the terms of the GNU General Public License version 2 or later.
-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>CollapsableWidget Test</title>
</head>
<body>

<script language="JavaScript" type="text/javascript" src="jsUnitTestLink.js"></script>
<script language="JavaScript" type="text/javascript" src="fitnesse.js"></script>
<script language="JavaScript" type="text/javascript">

  var body = document.getElementsByTagName("body")[0];
  var div1 = makeDiv("345");
  var img1 = makeImg("345");
  var div2 = makeDiv("789");
  var img2 = makeImg("789");
  body.appendChild(div1);
  body.appendChild(div2);
  div1.appendChild(img1);
  div2.appendChild(img2);

  function setOpen(div, img)
  {
    div.className = collapsableOpenCss;
    img.src = collapsableOpenImg;
  }

  function setClosed(div, img)
  {
    div.className = collapsableClosedCss;
    img.src = collapsableClosedImg;
  }

  function verifyOpen(div, img)
  {
    assertEquals(collapsableOpenCss, div.className);
    assertTrue(img.src.indexOf("Open") > -1);
  }

  function verifyClosed(div, img)
  {
    assertEquals(collapsableClosedCss, div.className);
    assertTrue(img.src.indexOf("Closed") > -1);
  }

  function testToggleCollapsableOpen()
  {
    setOpen(div1, img1);
    toggleCollapsable("345");
    verifyClosed(div1, img1);
  }

  function testToggleCollapsableClosed()
  {
    setClosed(div1, img1);
    toggleCollapsable("345");
    verifyOpen(div1, img1);
  }

  function testCollapseAllAllOpen()
  {
    setOpen(div1, img1);
    setOpen(div2, img2);
    collapseAll();
    verifyClosed(div1, img1);
    verifyClosed(div2, img2);
  }

  function testCollapseAllOneOpenOneClosed()
  {
    setOpen(div1, img1);
    setClosed(div2, img2);
    collapseAll();
    verifyClosed(div1, img1);
    verifyClosed(div2, img2);
  }

  function testExpandAll()
  {
    setClosed(div1, img1);
    setClosed(div2, img2);
    expandAll();
    verifyOpen(div1, img1);
    verifyOpen(div2, img2);
  }

  function testExpandAllOneOpenOneClosed()
  {
    setOpen(div1, img1);
    setClosed(div2, img2);
    expandAll();
    verifyOpen(div1, img1);
    verifyOpen(div2, img2);
  }

  function makeImg(id)
  {
    img = document.createElement("img");
    img.setAttribute("id", "img" + id)
    return img;
  }

  function makeDiv(id, className)
  {
    div = document.createElement("div");
    div.setAttribute("id", id);
    div.setAttribute("class", className);
    return div;
  }


</script>
</body>
</html>
